#include "task_data.hpp"
#include "events_cb.hpp"

#include <glog/logging.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <boost/xpressive/xpressive_dynamic.hpp>
task_data::task_data(/* args */)
{
}

task_data::~task_data()
{
}
void task_data::set_event_callback(bufferevent* buffer,void* arg)
{
    bufferevent_setcb(buffer,events_cb::event_read_cb,0,0,this);
    bufferevent_enable(buffer,EV_READ|EV_WRITE);
}
void task_data::recv_msg(std::string msg)
{
    if(!m_cmd_task|| !m_cmd_task->m_data_buffer)
    {
        VLOG(0)<<"recv_msg error";
        return;
    }
    if(msg[msg.size()-1]!='\n')
    {
        msg+='\r\n';
    }
    VLOG(0)<<"recv_msg      "<<msg;
    bufferevent_write(m_cmd_task->m_data_buffer,msg.c_str(),msg.size());
}
bool task_data::check_ip(const char *ip)
{
    boost::xpressive::cregex reg_ip = boost::xpressive::cregex::compile("(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[.](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])[.](25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])"); 
    return boost::xpressive::regex_match(ip,reg_ip);
}